package com.linwen.javase.juc;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @ClassName _08HashMapThread
 * @Description
 * @Author lin
 * @Date 2022/4/21 上午12:31
 * @Version V1.0
 *
 * hashmap也是线程不安全的类
 *
 * 1 使用hashTable  不推荐，过时
 * 2 使用ConcurrentHashMap
 */
public class _08HashMapThread {
    public static void main(String[] args) {
        // Map<String, String> map = new HashMap<>();
        // Map<String, String> map = new Hashtable<>();
        Map<String, String> map = new ConcurrentHashMap<>();
        for (int i = 0; i < 100; i++) {
            String s = String.valueOf(i);
            new Thread(()->{
                map.put(s,s);
                System.out.println(map);
            }).start();
        }
    }
}
